<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2007/03/28 11:12:22 $)
// $RCSfile: core.php,v $ : $Revision: 1.30 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

define("EXPORT_ALL", "1");
define("EXPORT_MODIFICATIONS", 2);

define("MODIFIED_USER", "user");
define("MODIFIED_UPGRADE", "upgrade");
define("MODIFIED_NONE", "notmodified");

define("USERGROUP_GUEST", "guest");
define("USERGROUP_REGISTERED", "registered");
define("USERGROUP_CUSTOM", "custom")
;
/**
* Default Core Module
*/
class core {
	/**
	* Constructor to register any events, sections
	*/
	function core() {
		global $_SWIFT, $events, $datastore;

		$events->registerEventModuleSWIFT(MODULE_CORE, $this);

		$events->registerEvent(EVENT_WINAPP, MODULE_CORE, "winapplogin");
		$events->registerEvent(EVENT_WINAPP, MODULE_CORE, "logout");
		
		// Client area
		$events->registerEvent(EVENT_CLIENT, MODULE_CORE, "login");
		$events->registerEvent(EVENT_CLIENT, MODULE_CORE, "logout");
		$events->registerEvent(EVENT_CLIENT, MODULE_CORE, "register");
		$events->registerEvent(EVENT_CLIENT, MODULE_CORE, "addcomment");
		$events->registerEvent(EVENT_CLIENT, MODULE_CORE, "myaccount");
		$events->registerEvent(EVENT_CLIENT, MODULE_CORE, "lostpassword");
		$events->registerEvent(EVENT_CLIENT, MODULE_CORE, "changepassword");
		$events->registerEvent(EVENT_CLIENT, MODULE_CORE, "searchclient");

		// Cron
		$events->registerEvent(EVENT_CRON, MODULE_CORE, "hourlycleanup");
		$events->registerEvent(EVENT_CRON, MODULE_CORE, "dailycleanup");


		// Diagnostics
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "phpinfo");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "mysqlinfo");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "cacheinfo");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "licenseinfo");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "activesessions");

		// Database
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "backup");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "repair");

		// Scheduled Tasks
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managetasks");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "tasklog");

		// Languages
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managelanguages");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "insertlanguage");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "editlanguage");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managephrases");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "searchlanguage");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "importexportlanguage");

		// Templates
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "importexporttemplates");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "inserttemplategroup");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managetemplategroups");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "edittemplategroup");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managetemplates");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "edittemplate");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "previewtemplate");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "manageloginshare");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "templatediagnostics");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "searchtemplates");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "restoretemplates");

		// Custom Fields
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managecfgroups");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managecfields");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "insertcfgroup");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "editcfgroup");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "insertcfield");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "editcfield");
		
		// Menu Items
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "help");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "settings");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "dashboard");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "insertdepartment");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managedepartments");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "editdepartment");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managestaff");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "insertstaff");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "editstaff");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "managestaffgroups");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "insertstaffgroup");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "editstaffgroup");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "staffactivitylog");
		$events->registerEvent(EVENT_ADMIN, MODULE_CORE, "staffmassmail");

		// Staff CP
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "dashboard");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "preferences");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "workschedule");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "privatemessages");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "privatemessagessent");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "viewprvmsg");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "composeprvmsg");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "manageusers");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "manageusergroups");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "insertuser");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "edituser");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "insertusergroup");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "editusergroup");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "usermassmail");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "edituseremail");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "editcomment");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "userlookup");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "changepassword");
		$events->registerEvent(EVENT_STAFF, MODULE_CORE, "al");

		// API
		$events->registerEvent(EVENT_API, MODULE_CORE, "api");

		$eventaction = $events->eventdata["eventaction"];
		$datastore->cache("departmentcache");
		$datastore->cache("staffgroupcache");
		$datastore->cache("groupsettingcache");
		$datastore->cache("languagecache");
		$datastore->cache("languagecache");
		$datastore->cache("prioritycache");
		$datastore->cache("statuscache");
		$datastore->cache("slaplancache");
		$datastore->cache("ticketcountcache");
		$datastore->cache("ticketlabelcache");
		$datastore->cache("labelcountcache");
		$datastore->cache("ticketfiltercache");
	}

	/**
	* Destructor, called to unregister any events etc
	*/
	function _core() {
	}

	/*
	* Callback function, for every event this function is called, $eventname is the passed $action variable
	*/
	function _eventcallback($eventtype, $eventaction)
	{
		global $_SWIFT, $interface, $template, $departments, $staffauth, $module, $grid, $xml, $staff, $settings, $dbCore, $events, $session, $loginshare, $cookie, $errormessage, $infomessage, $permissions, $mimelist, $registry;

		if ($eventtype == EVENT_WINAPP && $eventaction == "winapplogin")
		{
			return $this->winappLogin();
		} else if ($eventtype == EVENT_WINAPP && $eventaction == "logout") {
			$this->winappLogout();
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "dashboard" || $eventaction == "help")) {
			require_once ("./modules/core/admin_dashboard.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && ($eventaction == "dashboard")) {
			require_once ("./modules/core/staff_dashboard.php");
			return true;
		} else if ($eventtype == EVENT_CLIENT && ($eventaction == "login" || $eventaction == "logout")) {
			require_once ("./modules/core/client_loginhandler.php");
			return true;
		} else if ($eventtype == EVENT_CRON && ($eventaction == "hourlycleanup" || $eventaction == "dailycleanup")) {
			require_once ("./modules/core/cron_cleanup.php");
			return true;
		} else if ($eventtype == EVENT_CLIENT && ($eventaction == "register")) {
			require_once ("./modules/core/client_misc.php");
			return true;
		} else if ($eventtype == EVENT_API && ($eventaction == "api")) {
			require_once ("./modules/core/api_main.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "insertdepartment" || $eventaction == "managedepartments" || $eventaction == "editdepartment")) {
			require_once ("./modules/core/admin_departments.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managelanguages" || $eventaction == "insertlanguage" || $eventaction == "importexportlanguage" || $eventaction == "searchlanguage" || $eventaction == "editlanguage" || $eventaction == "managephrases")) {
			require_once ("./modules/core/admin_languages.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "importexporttemplates" || $eventaction == "inserttemplategroup" || $eventaction == "managetemplategroups" || $eventaction == "edittemplategroup" || $eventaction == "managetemplates" || $eventaction == "edittemplate" || $eventaction == "previewtemplate" || $eventaction == "templatediagnostics" || $eventaction == "manageloginshare" || $eventaction == "searchtemplates")) {
			require_once ("./modules/core/admin_templates.php");
			return true;
		}else if ($eventtype == EVENT_ADMIN && ($eventaction == "restoretemplates")){
			require_once("./modules/core/admin_restoretemplates.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managecfgroups" || $eventaction == "managecfields" || $eventaction == "insertcfgroup" || $eventaction == "editcfgroup" || $eventaction == "insertcfield" || $eventaction == "editcfield")) {
			require_once ("./modules/core/admin_customfields.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managestaff" || $eventaction == "insertstaff" || $eventaction == "editstaff" || $eventaction == "managestaffgroups" || $eventaction == "insertstaffgroup" || $eventaction == "staffmassmail" || $eventaction == "editstaffgroup")) {
			require_once ("./modules/core/admin_staff.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && ($eventaction == "preferences" || $eventaction == "workschedule" || $eventaction == "changepassword")) {
			require_once ("./modules/core/staff_preferences.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && ($eventaction == "privatemessages" || $eventaction == "viewprvmsg" || $eventaction == "composeprvmsg" || $eventaction == "privatemessagessent")) {
			require_once ("./modules/core/staff_privatemessages.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && ($eventaction == "manageusers" || $eventaction == "manageusergroups" || $eventaction == "insertuser" || $eventaction == "edituser" || $eventaction == "insertusergroup" || $eventaction == "editusergroup" || $eventaction == "usermassmail" || $eventaction == "edituseremail")) {
			require_once ("./modules/core/staff_users.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "backup" || $eventaction == "repair")) {
			require_once ("./modules/core/admin_database.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "phpinfo" || $eventaction == "mysqlinfo" || $eventaction == "cacheinfo" || $eventaction == "licenseinfo" || $eventaction == "activesessions")) {
			require_once ("./modules/core/admin_diagnostics.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managetasks" || $eventaction == "tasklog")) {
			require_once ("./modules/core/admin_tasks.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && $eventaction == "settings") {
			require_once ("./modules/core/admin_settings.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && $eventaction == "userlookup") {
			require_once ("./modules/core/staff_userlookup.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && $eventaction == "editcomment") {
			require_once ("./modules/core/staff_comments.php");
			return true;
		} else if ($eventtype == EVENT_CLIENT && $eventaction == "addcomment") {
			require_once ("./modules/core/client_comments.php");
			return true;
		} else if ($eventtype == EVENT_CLIENT && $eventaction == "searchclient") {
			require_once ("./modules/core/client_search.php");
			return true;
		} else if ($eventtype == EVENT_CLIENT && $eventaction == "lostpassword") {
			require_once ("./modules/core/client_lostpassword.php");
			return true;
		} else if ($eventtype == EVENT_CLIENT && $eventaction == "changepassword") {
			require_once ("./modules/core/client_changepassword.php");
			return true;
		} else if ($eventtype == EVENT_CLIENT && $eventaction == "myaccount") {
			require_once ("./modules/core/client_myaccount.php");
			return true;
		}
		return false;
	}
}
?>